package com.cloud.tsp.controller;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.model.OilModelInformation;
import com.cloud.core.exception.MyException;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.tsp.service.IOilModelInformationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-25
 */
@RestController
@RequestMapping("/oil-model-information")
public class OilModelInformationController {

    @Resource
    private IOilModelInformationService oilModelInformationService;

    @Tag(name = "v1.0")
    @Operation(summary = "根据车型查询油车全部车型信息（管理）")
    @PostMapping("/getByModelId")
    @Log(title = "车型管理-根据车型查询油车全部车型信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<OilModelInformation> selectByModelId(@RequestBody @Valid StrVo para){
        return R.ok(oilModelInformationService.getById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改车型基础信息（管理）")
    @PostMapping("/InsertOrUpdate")
    @Log(title = "车型管理-新增或修改车型基础信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdate(@RequestBody @Valid OilModelInformation para){
        oilModelInformationService.saveOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "油车基本信息导出")
    @PostMapping("/exportOilInformation")
    @Log(title = "车型管理-油车基本信息导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportOilInformation(String id, HttpServletResponse response) throws IOException {
        if (StringUtil.isBlank(id)){
            throw new MyException("wds.exception.idNull");
        }
        oilModelInformationService.exportOilInformation(id,response);
    }
}